
function timeZero(n) {
    return n < 10 ? "0" + n : n;
  }
  template.defaults.imports.dateFormate = function (cdate) {
    console.log(cdate);
    let date = new Date(cdate);
    let year = date.getFullYear();
    let mouth = date.getMonth() + 1;
    let day = date.getDate();
    let h = date.getHours();
    let min = date.getMinutes();
    let sec = date.getSeconds();
    return `${year}-${timeZero(mouth)}-${timeZero(day)} ${timeZero(h)}:${timeZero(
      min
    )}:${timeZero(sec)}`;
  };

function getCate() {
    // 获取
    $.ajax({
        type: 'GET',
        url: '/admin/comments',
        success: function (res) {
            const temp = template('table', res)
            $('tbody').html(temp)
        }
    })
}
getCate()

// 删除
$('body').on('click', '.remove', function () {
    console.log($(this).attr('data-id'));
    // 打开弹窗
    layui.layer.confirm('确定要删除吗？', {}, index => {
        $.ajax({
            url: '/admin/comments/' + $(this).attr('data-id'),
            method: 'DELETE',
            success: function (res) {
                layui.layer.close(index)
                layui.layer.msg(res.message)
                getCate()
                console.log(res);
            }
        })
    })
})